package com.classify.system.service.impl;

import java.util.List;

import com.classify.system.domain.SgClassifyPO;
import com.classify.system.domain.SgClassifyVO;
import com.shopgoods.common.core.domain.R;
import com.shopgoods.system.api.RemoteFileService;
import com.shopgoods.system.api.domain.SysFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.classify.system.mapper.SgClassifyMapper;
import com.classify.system.domain.SgClassify;
import com.classify.system.service.ISgClassifyService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商品分类Service业务层处理
 *
 * @author shopgoods
 * @date 2024-11-14
 */
@Service
public class SgClassifyServiceImpl implements ISgClassifyService
{
    @Autowired
    private SgClassifyMapper sgClassifyMapper;
    @Autowired
    private RemoteFileService remoteFileService;

    /**
     * 查询商品分类
     *
     * @param classifyId 商品分类主键
     * @return 商品分类
     */
    @Override
    public SgClassify selectSgClassifyByClassifyId(Integer classifyId)
    {
        return sgClassifyMapper.selectSgClassifyByClassifyId(classifyId);
    }

    /**
     * 查询商品分类列表
     *
     * @param sgClassify 商品分类
     * @return 商品分类
     */
    @Override
    public List<SgClassify> selectSgClassifyList(SgClassify sgClassify)
    {
        return sgClassifyMapper.selectSgClassifyList(sgClassify);
    }

    /**
     * 新增商品分类
     *
     * @param sgClassify 商品分类
     * @return 结果
     */
    @Override
    public int insertSgClassify(SgClassifyPO sgClassify)
    {
        return sgClassifyMapper.insertSgClassify(sgClassify);
    }

    /**
     * 修改商品分类
     *
     * @param sgClassify 商品分类
     * @return 结果
     */
    @Override
    public int updateSgClassify(SgClassifyVO sgClassify)
    {
        return sgClassifyMapper.updateSgClassify(sgClassify);
    }

    /**
     * 批量删除商品分类
     *
     * @param classifyIds 需要删除的商品分类主键
     * @return 结果
     */
    @Override
    public int deleteSgClassifyByClassifyIds(Integer[] classifyIds)
    {
        return sgClassifyMapper.deleteSgClassifyByClassifyIds(classifyIds);
    }

    /**
     * 删除商品分类信息
     *
     * @param classifyId 商品分类主键
     * @return 结果
     */
    @Override
    public int deleteSgClassifyByClassifyId(Integer classifyId)
    {
        return sgClassifyMapper.deleteSgClassifyByClassifyId(classifyId);
    }

    @Override
    public R<SysFile> avatar(MultipartFile file) {

        if (!file.isEmpty()){
            R<SysFile> upload = remoteFileService.upload(file);
            return upload;
        }
        return new R<>().fail("上传图片异常，请联系管理员");
    }

    @Override
    public List<SgClassify> selectSgClassifyNextList(Integer parentCategoryId)
    {
        return sgClassifyMapper.selectSgClassifyNextList(parentCategoryId);
    }

    @Override
    public int updateClassifyisInNavbarData(SgClassify sgClassify) {
        return sgClassifyMapper.updateClassifyisInNavbarData(sgClassify);
    }

    @Override
    public int updateClassifyisDisplayedData(SgClassify sgClassify) {
        return sgClassifyMapper.updateClassifyisDisplayedData(sgClassify);
    }

    @Override
    public List<SgClassify> treeselect() {
        return sgClassifyMapper.treeselect();
    }

    @Override
    public List<SgClassify> getNextList(Integer classifyId) {
        return sgClassifyMapper.getNextList(classifyId);
    }
}
